use base_data::channel::EndReason;
use tools::enum_generator;

enum_generator! {
	;
	ShChannelState{
		SCallStandby("空闲",0),
		SCallPickuped("摘机",1),
		SCallRinging("振铃",2),
		SCallTalking("通话",3),
		SCallAnalogWaitdialtone("模拟中继线通道:去话呼叫,等待拨号音",4),
		SCallAnalogTxphonum("模拟中继线通道:去话呼叫,拨号",5),
		SCallAnalogWaitdialresult("模拟中继线通道:去话呼叫,等待拨号结果",6),
		SCallPending("挂起状态。函数SsmGetPendingReason可以用来取得挂起原因",7),
		SCallOffline("线路断开状态",8),
		SCallWaitRemotePickup("去话呼叫,等候被叫用户摘机",9),
		SCallAnalogClear("模拟中继线通道:内部状态",10),
		SCallUnavailable("通道不可用",11),
		SCallLocked("呼出锁定",12),
		SCallRemoteBlock("对端闭塞",19),
		SCallLocalBlock("本地闭塞",20),
		SCallSs1inWaitPhoNum("SS1通道:接收被叫号码",30),
		SCallSs1inWaitFwdStop("SS1通道:等待对端交换机停发前向信号",31),
		SCallSs1inWaitCallerId("SS1通道:接收CallerID",32),
		SCallSs1inWaitKd("SS1通道:接收KD信号",33),
		SCallSs1inWaitKdstop("SS1通道:等待对端交换机停发KD信号",34),
		SCallSs1Sayidle("SS1通道:向对端交换机发送示闲信号",35),
		SCallSs1waitIdleCas("SS1通道:等待对端交换机的示闲信令",36),
		SCallSs1phoNumHoldup("SS1通道:号码拦截状态",37),
		SCallSs1inWaitStopSendA3p("SS1通道:等待对端交换机停发脉冲方式的A3信号",38),
		SCallSs1outWaitBwdAck("SS1通道:等待对端交换机应答占用证实信号",40),
		SCallSs1outTxPhoNum("SS1通道:发送被叫号码",41),
		SCallSs1outWaitAppendPhoNum("SS1通道:等待应用程序追加电话号码",42),
		SCallSs1outTxCallerId("SS1通道:发送主叫号码",43),
		SCallSs1outWaitKb("SS1通道:等待对端交换机的KB信号",44),
		SCallSs1outDetectA3p("SS1通道:等待对端交换机的A3脉冲信号",45),
		SFaxRound("FAX通道:状态转移过程中",50),
		SFaxPhaseA("FAX通道:传真呼叫建立(PhaseA)",51),
		SFaxPhaseB("FAX通道:传真报文前处理(PhaseB)",52),
		SFaxSendDcs("FAX通道:传真发送中向接收方发送DCS信号",53),
		SFaxTrain("FAX通道:传真报文传输前传输训练",54),
		SFaxPhaseC("FAX通道:传真报文传输中(PhaseC)",55),
		SFaxPhaseD("FAX通道:传真报文后处理(PhaseD)",56),
		SFaxNextPage("FAX通道:传真报文传输下一页",57),
		SFaxAllSent("FAX通道:传真发送中报文传输结束",58),
		SFaxPhaseE("FAX通道:传真呼叫释放(PhaseE)",59),
		SFaxReset("FAX通道:复位MODEM",60),
		SFaxInit("FAX通道:初始化MODEM",61),
		SFaxRcvDcs("FAX通道:传真接收,接收发方的DCS信号",62),
		SFaxSendFtt("FAX通道:传真接收,发送训练失败信号FTT",63),
		SFaxSendCfr("FAX通道:传真接收,发送可接受的证实信号CFR",64),
		SFaxSendPps("FAX通道:传真发送,ECM模式下,传真进行后续协商",65),
		SFaxRcvPpr("FAX通道:传真发送PPS后接收PPR信号",66),
		SFaxRepeatEcmpage("FAX通道:传真发送,ECM模式下,传真进行数据重发",67),
		SFaxCtcCtr("FAX通道:ECM模式下,4次重发后,进行肯定协商",68),
		SFaxSendPpr("FAX通道:ECM模式下,要求发送方重新发送数据",69),
		STupWaitPcmReset("TUP通道:电路复原",70),
		STupWaitSam("TUP通道:等待对端交换机的后续地址消息",71),
		STupWaitGsm("TUP通道:等待对端交换机的GSM消息",72),
		STupWaitClf("TUP通道:等待对端交换机的拆线消息",73),
		STupWaitPrefix("TUP通道:接收入局字冠",74),
		STupWaitDialAnswer("TUP通道:等待对端交换机的消息回应",75),
		STupWaitRlg("TUP通道:等待对端交换机的RLG消息",76),
		STupWaitSetCallerId("TUP通道:等待应用程序设置主叫号码",77),
		SIsdnOutWaitNetResponse("ISDN通道:等待网络响应",81),
		SIsdnOutPlsAppendNo("ISDN通道:等待应用程序追加号码",82),
		SIsdnInChkCallIn("ISDN通道:检测到呼入",83),
		SIsdnInRcvingNo("ISDN通道:正在接收号码",84),
		SIsdnInWaitTalk("ISDN通道:准备进入通话",85),
		SIsdnOutWaitAlert("ISDN通道:等待对方发提醒信号",86),
		SIsdnCallBegin("ISDN通道:发起呼叫(去话),或检测到呼入(来话)",87),
		SIsdnWaitHuangup("ISDN通道:等待挂机",88),
		SIsdnInCallProceeding("ISDN通道:呼叫进程",89),
		SCallSendring("磁石通道:发送振铃",100),
		SSpyRcvphonum("监控通道:接收号码",105),
		SSpySs1reset("SS1监控:复原",110),
		SSpySs1waitbwdack("SS1监控:等待后向证实",111),
		SSpySs1waitkb("SS1监控:等待KB",112),
		SIsupWaitSam("ISUP通道:等待对端交换机的SAM",120),
		SIsupWaitRlc("ISUP通道:等待对端交换机的释放监护信号RLC",121),
		SIsupWaitReset("ISUP通道:电路复原",122),
		SIsupLocallyBlocked("ISUP通道:本地闭塞",123),
		SIsupRemotelyBlocked("ISUP通道:远端闭塞",124),
		SIsupWaitDialAnswer("ISUP通道:等待对端交换机的消息回应",125),
		SIsupWaitInf("ISUP通道:等待对端交换机的INF消息",126),
		SIsupWaitSetCallerId("ISUP通道:等待应用程序设置主叫号码",127),
		SDtrcActive("DTR通道:被监控话路处于非空闲状态",128),
		SIsupSuspend("ISUP通道:暂停",129),
		SCallEmTxphonum("E/M通道:拨号或变声资源被占用",130),
		SCallEmWaitIdleCas("E/M通道:等待对端的示闲信号",131),
		SCallVoipDialing("IP通道:VoIP主叫拨号状态",132),
		SCallVoipWaitConnected("IP通道:VoIP被叫摘机等待进入通话状态",133),
		SCallVoipChannelUnusable("IP通道:VoIP通道目前不可用",134),
		SCallDisconect("USB连接断开",135),
		SCallSs1waitFlashEnd("SS1通道:等待闪断发送结束",136),
		SCallFlashEnd("SS1通道:闪断结束",137),
		SCallSignalError("DTR通道:帧同步正常但信号不完整",139),
		SCallFrameError("DTR通道:帧同步不正常但信号完整",140),
		SCallVoipSessionProceeding("IP通道:会话进行,该值为收到183时的状态",150),
		SCallVoipRegIng("IP通道:SIP通道注册中",151),
		SCallVoipRegFailed("IP通道:SIP通道注册失败",152),
		SCallVoipCallOnHold("IP通道:SIP通道呼叫保持状态",153),
		SIpMediaLock("MEDIA媒体通道:媒体通道锁定状态",160),
		SIpMediaOpen("MEDIA媒体通道:媒体通道打开状态",161),
		SSpyRbswaitack("RBS监控通道:等待应答",162),
		SSpyRbssendack("RBS监控通道:发送应答",163),
		SIprUsing("IPR系列产品通道:通道被占用状态",170),
		SIprCommunicating("IPR系列产品通道:通道处于通讯中",171),
		SIsupWaitCot("ISUP通道:等待COT消息",172),
	}

}

enum_generator! {
	;
	ShEvent{
		EProcRecognize("语音识别结束",0x0000),
		EChgIsdnstatus("E_CHG_ISDNStatus",0x0001),
		ERcvSs7msu("SS7：从 SS7 服务器收到新的消息（MSU）",0x0002),
		EChgMtp3state("E_CHG_Mtp3State",0x0003),
		EChgFaxChState("E_CHG_FaxChState",0x0004),
		EChgFaxPages("E_CHG_FaxPages",0x0005),
		EProcFaxEnd("E_PROC_FaxEnd",0x0006),
		EChgPcmLinkStatus("数字中继线的同步状态发生变化",0x0007),
		EChgLineVoltage("E_CHG_LineVoltage",0x0008),
		ERcvCas("E_RCV_CAS",0x0009),
		ERcvR2("E_RCV_R2",0x000a),
		EProcWaitDtmf("WaitDTMF任务完成",0x000b),
		EChgRcvDtmf("收到一个DTMF字符",0x000c),
		EProcSendDtmf("发送DTMF的任务完成",0x000d),
		EProcSendFlash("发送闪断信号的任务完成",0x000e),
		EProcPlayEnd("放音任务结束",0x000f),
		EProcPlayFile("E_PROC_PlayFile",0x0010),
		EProcPlayFileList("E_PROC_PlayFileList",0x0011),
		EProcPlayMem("E_PROC_PlayMem",0x0012),
		EProcRecordEnd("录音任务终止",0x0013),
		EProcRecordFile("E_PROC_RecordFile",0x0014),
		EProcRecordMem("E_PROC_RecordMem",0x0015),
		EProcSendFsk("E_PROC_SendFSK",0x0016),
		EProcRcvFsk("E_PROC_RcvFSK",0x0017),
		EChgChState("通道状态发生变化",0x0018),
		EProcAutoDial("AutoDial 任务有进展",0x0019),
		EChgRemoteChBlock("E_CHG_RemoteChBlock",0x001a),
		EChgRemotePcmblock("E_CHG_RemotePCMBlock",0x001b),
		ESysActualPickup("E_SYS_ActualPickup",0x001c),
		EChgRingFlag("E_CHG_RingFlag",0x001d),
		EChgRingCount("E_CHG_RingCount",0x001e),
		EChgCidexBuf("E_CHG_CIDExBuf",0x001f),
		EChgRxPhoNumBuf("收到新的被叫号码",0x0020),
		EChgPolarRvrsCount("E_CHG_PolarRvrsCount",0x0021),
		ESysRemotePickup("E_SYS_RemotePickup",0x0022),
		EChgFlashCount("在电话机上检测到一次闪断操作",0x0023),
		EChgHookState("话机上检测到摘机或挂机动作",0x0024),
		EChgToneAnalyze("分析结果发生变化",0x0025),
		EOverallEnergy("E_OverallEnergy",0x0026),
		EChgOvrlEnrgLevel("E_CHG_OvrlEnrgLevel",0x0027),
		EChgBusyTone("E_CHG_BusyTone",0x0028),
		EChgBusyToneEx("E_CHG_BusyToneEx",0x0029),
		EChgVocFxFlag("E_CHG_VocFxFlag",0x002a),
		EChgToneValue("E_CHG_ToneValue",0x002b),
		EChgRingEchoToneTime("E_CHG_RingEchoToneTime",0x002c),
		EChgPeakFrq("E_CHG_PeakFrq",0x002d),
		ESysBargeIn("E_SYS_BargeIn",0x002e),
		ESysNoSound("E_SYS_NoSound",0x002f),
		ESysTimeout("由函数 SsmStartTimer 启动的定时器发生溢出",0x0030),
		EChgSpyState("电路的状态发生变化",0x0031),
		EChgSpyLinkStatus("E_CHG_SpyLinkStatus",0x0032),
		ERcvDtrAudio("E_RCV_DTR_AUDIO",0x0033),
		ERcvDtrHook("E_RCV_DTR_HOOK",0x0034),
		ERcvDtrLamp("E_RCV_DTR_LAMP",0x0035),
		ERcvDtrFkey("E_RCV_DTR_FKEY",0x0036),
		ERcvDtrDkey("E_RCV_DTR_DKEY",0x0037),
		ERcvDtrVox("E_RCV_DTR_VOX",0x0038),
		ERcvDtrDisplay("E_RCV_DTR_DISPLAY",0x0039),
		ERcvDtrDirection("E_RCV_DTR_DIRECTION",0x003a),
		ERcvDtrRing("E_RCV_DTR_RING",0x003b),
		EChgCicrxPhoNumBuf("E_CHG_CICRxPhoNumBuf",0x003c),
		EChgCicstate("E_CHG_CICState",0x003d),
		EProcCicautoDial("E_PROC_CICAutoDial",0x003e),
		ERcvSs7isupUtuinf("E_RCV_Ss7IsupUtuinf",0x003f),
		EChgMtp2status("SS7信令链路的状态发生变化",0x0040),
		ERcvDstdchannel("E_RCV_DSTDChannel",0x0041),
		ERcvSs7spyMsu("E_RCV_Ss7SpyMsu",0x0042),
		EChgToneDetector("E_CHG_ToneDetector",0x0043),
		EChgToneDetectorItem("E_CHG_ToneDetectorItem",0x0044),
		ERcvCallerid("E_RCV_CALLERID",0x0045),
		EProcFaxDcnTag("E_PROC_FaxDcnTag",0x0046),
		EChgAmd("E_CHG_AMD",0x0047),
		ERcvSs7isupCpg("E_RCV_Ss7IsupCpg",0x0048),
		EChgCbChStatus("E_CHG_CbChStatus",0x0049),
		ERcvSs7mtp2msu("E_RCV_SS7Mtp2Msu",0x004a),
		EReferStatus("E_REFER_Status",0x0050),
		EChgSpyHangupInfo("E_CHG_SpyHangupInfo",0x0051),
		EChgCallBackRingCount("E_CHG_CallBackRingCount",0x0052),
		EChgRcvMf("E_CHG_RcvMF",0x0053),
		EChgPcm32lineState("E_CHG_Pcm32LineState",0x0054),
		ERcvSpyCas("E_RCV_SPY_CAS",0x0055),
		EChgRingEchoToneCnt("E_CHG_RingEchoToneCnt",0x0056),
		ESs7L2toL3Ind("E_Ss7_L2ToL3_IND",0x0057),
		ERcvIprDchannel("E_RCV_IPR_DChannel",0x0060),
		ERcvIprDongleAdded("E_RCV_IPR_DONGLE_ADDED",0x0061),
		ERcvIprDongleRemoved("E_RCV_IPR_DONGLE_REMOVED",0x0062),
		ERcvIprNicLinked("E_RCV_IPR_NIC_LINKED",0x0063),
		ERcvIprNicUnlinked("E_RCV_IPR_NIC_UNLINKED",0x0064),
		ERcvIprAuthOverflow("E_RCV_IPR_AUTH_OVERFLOW",0x0065),
		ERcvIprMediaSessionStarted("E_RCV_IPR_MEDIA_SESSION_STARTED",0x0066),
		ERcvIprMediaSessionStoped("E_RCV_IPR_MEDIA_SESSION_STOPED",0x0067),
		ERcvIprAuxMediaSessionStarted("E_RCV_IPR_AUX_MEDIA_SESSION_STARTED",0x0068),
		ERcvIprMediaSessionFowarding("E_RCV_IPR_MEDIA_SESSION_FOWARDING",0x0069),
		ERcvIprMediaSessionFowardStoped("E_RCV_IPR_MEDIA_SESSION_FOWARD_STOPED",0x006a),
		ERcvIprStationAdded("E_RCV_IPR_STATION_ADDED",0x006b),
		ERcvIprStationRemoved("E_RCV_IPR_STATION_REMOVED",0x006c),
		EIprLinkRecSlaverConnected("E_IPR_LINK_REC_SLAVER_CONNECTED",0x006d),
		EIprLinkRecSlaverDisconnected("E_IPR_LINK_REC_SLAVER_DISCONNECTED",0x006e),
		EIprSlaverInitCb("E_IPR_SLAVER_INIT_CB",0x006f),
		EIprActiveSessionCb("E_IPR_ACTIVE_SESSION_CB",0x0070),
		EIprDeactiveSessionCb("E_IPR_DEACTIVE_SESSION_CB",0x0071),
		EIprStartRecCb("E_IPR_START_REC_CB",0x0072),
		EIprStopRecCb("E_IPR_STOP_REC_CB",0x0073),
		EIprPauseRecCb("E_IPR_PAUSE_REC_CB",0x0074),
		EIprRestartRecCb("E_IPR_RESTART_REC_CB",0x0075),
		EIprStartSlaverCb("E_IPR_START_SLAVER_CB",0x0076),
		EIprCloseSlaverCb("E_IPR_CLOSE_SLAVER_CB",0x0077),
		EIprRcvDtmf("E_IPR_RCV_DTMF",0x0078),
		EIprActiveAndRecCb("E_IPR_ACTIVE_AND_REC_CB",0x0079),
		EIprDeactiveAndStoprecCb("E_IPR_DEACTIVE_AND_STOPREC_CB",0x007a),
		ERcvIpaDongleAdded("E_RCV_IPA_DONGLE_ADDED",0x007b),
		ERcvIpaDongleRemoved("E_RCV_IPA_DONGLE_REMOVED",0x007c),
		ERcvIpaApplicationPending("E_RCV_IPA_APPLICATION_PENDING",0x007d),
		ERcvIprAuxMediaSessionStoped("E_RCV_IPR_AUX_MEDIA_SESSION_STOPED",0x007e),
		EBoardIcmpChange("E_BOARD_ICMP_CHANGE",0x007F),
		ERcvIsdnSpyMsu("E_RCV_IsdnSpyMsu",0x0080),
		ERcvDecodeSs7msu("E_RCV_DecodeSs7Msu",0x0081),
		EChgRcvSelcall("E_CHG_RCV_SELCALL",0x0082),
		ERcvIsdnL2spyMsu("E_RCV_IsdnL2SpyMsu",0x0083),
		EChgAmdTime("E_CHG_AMD_TIME",0x0084),
		ERegOptionsResponse("E_REG_OPTIONS_RESPONSE",0x0085),
		ERcvHmpDongleAdded("E_RCV_HMP_DONGLE_ADDED",0x0086),
		ERcvHmpDongleRemoved("E_RCV_HMP_DONGLE_REMOVED",0x0087),
		ERegRequest("E_REG_REQUEST",0x0088),
		ERegRegstatus("E_REG_REGSTATUS",0x0089),
		ERcvRefer("E_RCV_REFER",0x008A),
		ERegNotifyResponse("E_REG_NOTIFY_RESPONSE",0x008b),
		ESipstackRegstatus("E_SIPSTACK_REGSTATUS",0x008c),
		EHoldingCall("E_HOLDING_CALL",0x008d),
		ESipResponse("E_SIP_RESPONSE",0x008e),
		ERcvIprIgmpMessage("E_RCV_IPR_IGMP_MESSAGE",0x008f),
		ESysLostInterrupt("E_SYS_Lost_Interrupt",0x0090),
		ESipstackPcmstate("E_SIPSTACK_PCMSTATE",0x0091),
		ESipSubscribe("E_SIP_SUBSCRIBE",0x0092),
		ERecEnergy("E_RecEnergy",0x0093),
	}
}

enum_generator! {
	;
	PendingReason{
		PendWaitBckStpMsg("来话呼叫：驱动程序按照预设的收号规则完成被叫号码",10),
		PendRemoteHangupOnTalking("来话呼叫：双方通话时，对端挂机",12),
		PendAutoDialFailed("去话呼叫失败。",13),
		PendSsxUnusable("SS7 信令不可用",14),
		PendCircuitReset("发生电路复原事件",15),
		PendPcmSyncLos("数字中继线的基本帧（0 时隙）同步信号丢失",16),
		PendCalleeHangupOnTalking("去话呼叫：双方通话时，对端挂机",20),
		Ss1outUndefinedBwdA("去话呼叫失败：收到未定义的后向 A 组信号",37),
		Ss1outUndefinedBwdKb("去话呼叫失败：收到未定义的 KB 信号",38),
		PendCalleeHangupOnWaitRemotePickUp("去话呼叫失败：等待被叫用户摘机时，收到对端交换机的拆线消息",48),
		IsupHardCircuitBlock("收到对端交换机的硬件闭塞消息",49),
		IsupRemoteSuspend("T6 定时器溢出。",50),
		PendRemoteHangupOnRinging("来话呼叫：通道处于“振铃”状态时，对端交换机取消了呼叫",54),
		PendRemoteHangupOnSuspend("“暂停”状态时，对端用户挂机",63),
		PendCalleeHangupOnSuspend("“暂停”状态时，被叫用户挂机",64),
	}
}

enum_generator! {
	;
	DialFailedReason{
		AtdlNull("没有呼出任务",0),
		AtdlCancel("AutoDial 任务被应用程序取消",1),
		AtdlWaitDialAnsTimeout("等待被叫应答超时",2),
		AtdlWaitRemotePickupTimeout("等待被叫摘机超时",3),
		AtdlPcmSyncLos("ATDL_PcmSyncLos",4),
		AtdlMtp3unusable("SS7 信令：信令不可用",10),
		AtdlRcvSsb("SS7 信令：收到对端交换机的 SSB 消息",11),
		AtdlRcvSlb("SS7 信令：收到对端交换机的 SLB 消息",12),
		AtdlRcvStb("SS7 信令：收到对端交换机的 STB 消息",13),
		AtdlRcvUnn("SS7 信令：收到对端交换机的 UNN 消息",14),
		AtdlRcvSec("SS7 信令：收到对端交换机的 SEC 消息",15),
		AtdlRcvCgc("SS7 信令：收到对端交换机的 CGC 消息",16),
		AtdlRcvNnc("SS7 信令：收到对端交换机的 NNC 消息",17),
		AtdlRcvCfl("SS7 信令：收到对端交换机的 CFL 消息",18),
		AtdlRcvLos("SS7 信令：收到对端交换机的 LOS 消息",19),
		AtdlRcvSst("SS7 信令：收到对端交换机的 SST 消息",20),
		AtdlRcvAcb("SS7 信令：收到对端交换机的 ACB 消息",21),
		AtdlRcvDpn("SS7 信令：收到对端交换机的 DPN 消息",22),
		AtdlRcvEum("SS7 信令：收到对端交换机的 EUM 消息",23),
		AtdlRcvAdi("SS7 信令：收到对端交换机的 ADI 消息",24),
		AtdlRcvBlo("SS7 信令：收到对端交换机的 BLO 消息",25),
		AtdlDoubleOccupy("SS7 信令：检出同抢",26),
		AtdlCircuitReset("SS7 信令：收到对端交换机的电路/群复原信号",27),
		AtdlBlockedByRemote("SS7 信令：电路被对端交换机闭塞",28),
		AtdlIllegalMessage("SS7 信令：收到对端交换机的非法消息",65),
		AtdlRcvRel("ISUP：收到对端交换机的释放消息(REL)",66),
		AtdlRcvCbk("TUP：收到对端交换机的 CBK 消息",67),
	}
}

///三汇板卡的转换挂断原因的方法
pub(crate) fn covert_to_hangup_reason(reason: (PendingReason, DialFailedReason)) -> EndReason {
	match reason {
		(PendingReason::PendAutoDialFailed, DialFailedReason::AtdlRcvRel) => {
			EndReason::CalledHangup("被叫挂断".to_owned())
		}
		_ => EndReason::UnknownValue,
	}
}
